package com.mzy.basics.pravatestructure;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * @author Ives
 * * @date 2021/11/23
 */
public class Test {


  @org.testng.annotations.Test
  public void test() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
    Class<Persion> persionClass = Persion.class;
//    Persion persion = persionClass.newInstance(); // 构造方法被私有化 无法通过反射创建类

    // 通过反射创建私有构造方法（单例）。
    Constructor<Persion> declaredConstructor = persionClass.getDeclaredConstructor();
    // 拿到构造类需要设置申请
    declaredConstructor.setAccessible(true);
    Persion a = declaredConstructor.newInstance();
    System.out.println(a);
    a.demo();
  }

}
